package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.UserBean;
import com.project.mapper.IUserMapper;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements IUserService {
    @Autowired
    private IUserMapper mapper;
    @Override
    public IPage<UserBean> findByItem(int pageNo, String account) {
        QueryWrapper<UserBean> qw = new QueryWrapper<>();
        if (account !=null && account.length() != 0){
            qw.like("u_account",account);

        }
        return mapper.selectPage(new Page<UserBean>(pageNo,PAGESIZE),qw);
    }

    @Override
    public void del(int id) {
        mapper.del(id);
    }

    @Override
    public void add(UserBean userBean, int[] roleArray) {
        mapper.insert(userBean);
        mapper.addRoleList(userBean.getId(),roleArray);
    }

    @Override
    public UserBean findById(int id) {
        return mapper.findById(id);
    }

    @Override
    public void updateRole(int id, int[] roleArray) {
        mapper.updateRole(id, roleArray);
    }
}
